trigger AccountPoshare on Purchase_Object__c (after insert, after update){
    Set<Id> PoId = New Set<Id>();
    Set<Id> AcId = New Set<Id>();
    List<Purchase_Object__c> poOwner = New List<Purchase_Object__c>();
    List<Purchase_Object__Share> ListPo = New List<Purchase_Object__Share>();
    List<Purchase_Object__Share> user = new List<Purchase_Object__Share>();
 for(Purchase_Object__c poObj : Trigger.New){
   PoId.add(poObj.Id);
   AcId.add(poObj.Account__c);
   }
 poOwner = [Select OwnerId from Purchase_Object__c where id in :PoId];
 user = [Select UserOrGroupId,ParentId from  Purchase_Object__Share where ParentId in :PoId]; 
 System.debug('userlist' + user);    

 list<AccountShare> AccShare = new list<AccountShare>();
 AccShare = [select Id,AccountId,UserOrGroupId,AccountAccessLevel from AccountShare where AccountId in :AcId];
 list<Purchase_Object__Share> POShare = new list<Purchase_Object__Share>();

 for(Purchase_Object__c po : trigger.new)
   {
   for(AccountShare AcShr: AccShare){
       Purchase_Object__Share pos = new Purchase_Object__Share();
       if(po.Account__c == AcShr.AccountId && AcShr.UserOrGroupId!=po.Ownerid){
                pos.ParentId = po.id;
                pos.AccessLevel = 'read' ;
                pos.UserOrGroupId = AcShr.UserOrGroupId;
                POShare.add(pos);
            }
    }  
   insert POShare;             
}
}